package collections;

import util.Tracer;

public class StackedQueue <T> {
	private Stack <T> in;
	private Stack <T> out;
	
	public StackedQueue(int capacity)
	{
		in = new Stack<T>(capacity);
		out = new Stack<T>(capacity);
	}
	
	public void enqueue(T t)
	{
		in.push(t);
	}
	
	public T dequeue()
	{
		if(out.isEmpty())
		{
			while(!in.isEmpty())
			{
				out.push(in.pop());
			}
		}
		
		return out.pop();
	}
	
	public static void main(String[] args) {
		StackedQueue<Integer> q = new StackedQueue<Integer>(5);
		q.enqueue(1);
		q.enqueue(2);
		q.enqueue(3);
		Tracer.trace(q.dequeue());
		Tracer.trace(q.dequeue());
		Tracer.trace(q.dequeue());
	}
}
